<?php
defined ( 'BASEPATH' ) or exit ( 'No direct script access allowed' );
class Project_participater extends CI_Controller {
	public function __construct() {
		parent::__construct ();
		$this->admin->isLogin ( site_url ( 'login' ) );
		$this->load->model("project_participater_model");
		$this->load->model("user_model");
	}
	/*
	 *参加首页 
	 */
	public function index($pid=1){
		$whereArr = array("pid"=>$pid,"status"=>1);
		$project_participater_list = $this->project_participater_model->resultAll($whereArr,"createtime@DESC");
		foreach($project_participater_list as $key => $value){
			$user = $this->change_uid_to_user($value['uid']);
			$project_participater_list[$key]['logo'] = ltrim($user['logo'],".");
			$project_participater_list[$key]['username'] = $user['username'];
		}
		$data['project_participater_list'] = $project_participater_list;
		$this->load->view("project_participater_index",$data);
	}
	/*
	 *对多人进行删除 
	 */
	public function duodel(){
		$ids = $this->input->post('ids');
		if(empty($ids))
		{
			$flag =array('status'=>-1,'info'=>'请选择数据!!');
		}else{
			$dataArr=array("status"=>0);
			$result=$this->project_participater_model->update_in($dataArr,'ppid',$ids);
			if($result){
				$flag = array('status'=>1,'info'=>'删除成功!');
			}else{
				$flag = array('status'=>0,'info'=>'删除失败!');
			}
		}
		echo json_encode($flag);
	} 
	/*
	 *对多人进行审核 
	 */
	public function duocheck(){
		$ids = $this->input->post('ids');
		if(empty($ids))
		{
			$flag =array('status'=>-1,'info'=>'请选择数据!!');
		}else{
			$dataArr=array("check"=>2);
			$result=$this->project_participater_model->update_in($dataArr,'ppid',$ids);
			if($result){
				$flag = array('status'=>1,'info'=>'参赛人员审核成功!');
			}else{
				$flag = array('status'=>0,'info'=>'参赛人员审核失败!');
			}
		}
		echo json_encode($flag);
	}
	/*
	 *对多人禁用 
	 */
	public function duoforbid(){
		$ids = $this->input->post('ids');
		if(empty($ids))
		{
			$flag =array('status'=>-1,'info'=>'请选择数据!!');
		}else{
			$dataArr=array("check"=>0);
			$result=$this->project_participater_model->update_in($dataArr,'ppid',$ids);
			if($result){
				$flag = array('status'=>1,'info'=>'参赛人员禁用成功!');
			}else{
				$flag = array('status'=>0,'info'=>'参赛人员禁用失败!');
			}
		}
		echo json_encode($flag);
	}
	/*
	 *对参加人进行审核 
	 */
	public function check($ppid=1){
		$whereArr = array("ppid"=>$ppid);
		$dataArr = array("check"=>2);
		$result = $this->project_participater_model->update($dataArr,$whereArr);
		if($result){
			$data['status'] = 1;
			$data['info'] = "审核成功!!";
		}else{
			$data['status'] = -1;
			$data['info'] = "审核失败!!";
		}
		echo json_encode($data);
	}
	/*
	 *禁用用户参加此项目
	 */
	public function forbid($ppid=1){
		$whereArr = array("ppid"=>$ppid);
		$dataArr = array("check"=>0);
		$result = $this->project_participater_model->update($dataArr,$whereArr);
		if($result){
			$data['status'] = 1;
			$data['info'] = "禁用成功!!";
		}else{
			$data['status'] = -1;
			$data['info'] = "禁用失败!!";
		}
		echo json_encode($data);
	}
	/*
	 *删除这用户 
	 */
	public function del($ppid=1){
		$whereArr = array("ppid"=>$ppid);
		$dataArr = array("status"=>0);
		$result = $this->project_participater_model->update($dataArr,$whereArr);
		if($result){
			$data['status'] = 1;
			$data['info'] = "删除成功!!";
		}else{
			$data['status'] = -1;
			$data['info'] = "删除失败!!";
		}
		echo json_encode($data);
	}
	/*
	 *根据用户id查找用户信息 
	 */
	public function change_uid_to_user($uid){
		$whereArr = array("uid"=>$uid);
		$user = $this->user_model->row($whereArr);
		if($user){
			return $user;
		}
	}
}